#include"client.h"

//bin baza
baza::baza(char *t, char * c)
{
	transmisie=new char[strlen(t)+1];
	strcpy(transmisie,t);
	culoare=new char[strlen(c)+1];
	strcpy(culoare,c);
}


//din sedan
void sedan::afisare()
{
	cout<<"Sedan"<<" : "<<culoare<<", "<<transmisie<<", "<<navigatie<<", "<<siguranta<<", "<<antidemaraj<<"; "<<endl;
}


//din coupe
void coupe::afisare()
{
	cout<<"Coupe"<<" : "<<culoare<<", "<<transmisie<<", "<< plafon<<", "<<jenti<<", "<<garantie<<" ani; "<<endl;
}

void mini::afisare()
{
	cout<<"Coupe"<<" : "<<culoare<<", "<<transmisie<<", "<< motorizare<<", "<<lungime<<", "<<consum<<" litri/100km; "<<endl;
}

/// din Manager

void Manager::add_client(char *n, int vr)
{
	v[nr++]=new client(n,vr);
}

void Manager::afisare()
{
	for ( int i=0; i<nr; i++ )
		v[i]->afisare();
}

bool Manager::instanceFlag = false;
Manager* Manager::single = NULL;
Manager* Manager::getInstance()
{
    if(! instanceFlag)
    {
        single = new Manager("Laur_auto");
        instanceFlag = true;
        return single;
    }
    else
    {
        return single;
    }
}


//din client
	client::client()
	{
		nume=new char[strlen("necunoscut")+1];
		strcpy(nume,"necunoscut");
		nr=0;
	}

	client::client(char *n, int v)
	{
		nume=new char[strlen(n)+1];
		strcpy(nume,n);
		varsta = v;
		nr=0;
	}

	void client::add_car(char *t,char *c,char *n, char *s, char *a)//Sedan
	{
		v[nr++]=new sedan(t,c,n,s,a);
	}

	void client::add_car(char *t,char *c,char *p, char *j, int g)//Coupe
	{
		v[nr++]=new coupe(t,c,p,j,g);
	}

	void client::add_car(char *t,char *c,char * m, char *lun, float con)//Mini
	{
		v[nr++]=new coupe(t,c,m,lun,con);
	}

	void client::afisare()
	{
		cout<<"sunt clientul cu nr_masini="<<nr<<" :"<<nume<<" de varsta "<<varsta<<"\n";
		for(int i=0;i<nr;i++)
			v[i]->afisare();
	}

	void client::del_produs(char *n)
	{
		int ok=1;
		if(nr==0)
			throw new exceptie("nu are masini in lista");
		else
			while(ok)
			{
				ok=0;
				for(int i=0;i<nr;i++)	
					if(strcmp(v[i]->get_culoare(),n)==0)
					{
						for(int j=i;j<nr-1;j++)
						{
							v[j]=v[j+1];
						}

						nr--;
						i--;
						ok=1;
					}
				
			}
		
	}
	